﻿// Study1203.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
// 第十二章 异常处理 标准异常类

#include <iostream>
#include <string>
#include <cmath>
#include <stdexcept>
using namespace std;

double area (double a,double b,double c)throw(invalid_argument)
{
	if (a<=0||b<=0||c<=0)
	{
		throw invalid_argument("边长不能为负数！");
	}
	if (a+b<=c||b+c<=a||a+c<=b)
	{
		throw invalid_argument("三边无法围成三角形") ;
	}
	double s = (a + b + c) / 2;
	return sqrt(s * (s - a) * (s - b) * (s - c));
}

int main()
{
	double a, b, c;
	cout << "输入三边：" << endl;
	cin >> a >> b >> c;
	try
	{
		double st = area(a, b, c);
		cout << "Area:" << st << endl;
	}
	catch (exception &e)
	{
		cout << "错误：" << e.what() << endl;
	}
	return 0;
}


